;;; GNU Guix --- Functional package management for GNU
;;;
;;; Copyright © 2021 florhizome <florhizome@posteo.net>
;;; Copyright © 2022 ( <paren@disroot.org>
;;;
;;; This file is not part of GNU Guix.
;;;
;;; GNU Guix is free software; you can redistribute it and/or modify it
;;; under the terms of the GNU General Public License as published by
;;; the Free Software Foundation; either version 3 of the License, or (at
;;; your option) any later version.
;;;
;;; GNU Guix is distributed in the hope that it will be useful, but
;;; WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;;; GNU General Public License for more details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with GNU Guix.  If not, see <http://www.gnu.org/licenses/>.

;;; module for utility packages/tools specifically for wayland and wlroots
;;; graphical environments

(define-module (guixrus packages wayland-xyz)
  #:use-module (guix download)
  #:use-module (guix git-download)
  #:use-module ((guix licenses) #:prefix license:)
  #:use-module (guix utils)
  #:use-module (guix build utils)
  #:use-module (guix gexp)
  #:use-module (guix packages)
  #:use-module (gnu packages)
  #:use-module (gnu packages admin)
  #:use-module (gnu packages base)
  #:use-module (guix build-system gnu)
  #:use-module (guix build-system meson)
  #:use-module (guix build-system cmake)
  #:use-module (gnu packages gtk)
  #:use-module (gnu packages lxde)
  #:use-module (gnu packages gnome)
  #:use-module (gnu packages version-control)
  #:use-module (gnu packages glib)
  #:use-module (gnu packages maths)
  #:use-module (gnu packages linux)
  #:use-module (gnu packages pkg-config)
  #:use-module (gnu packages freedesktop)
  #:use-module (gnu packages gl)
  #:use-module (gnu packages xorg)
  #:use-module (gnu packages xml)
  #:use-module (gnu packages python-xyz)
  #:use-module (gnu packages pulseaudio)
  #:use-module (gnu packages cpp)
  #:use-module (gnu packages wm)
  #:use-module (gnu packages xdisorg)
  #:use-module ((guixrus packages misc) #:prefix rus:))

;; I tried to build it from the latest github commit, since the
;; latest release is pretty old but it fails at installing man-pages.
;; disabling man pages via configure flag didn't help.
(define-public lxappearance-gtk3-wayland
  (package
    (inherit lxappearance)
    (name "lxappearance-gtk3-wayland")
    (version "0.6.3")
    (source
     (origin
       (method url-fetch)
       (uri
        (string-append "mirror://sourceforge/lxde/"
                       "LXAppearance/lxappearance-" version ".tar.xz"))
       (sha256
        (base32 "0f4bjaamfxxdr9civvy55pa6vv9dx1hjs522gjbbgx7yp1cdh8kj"))
       (patches
        (parameterize
            ((%patch-path
              (map
               (lambda (directory)
                 (string-append directory "/guixrus/packages/patches"))
               %load-path)))
        (search-patches
         ;;patches created from github issues
         "lxappearence-gtk3-01-only-do-x11-on-x11.patch"
         "lxappearence-gtk3-02-set-some-settings-gsettings.patch")))))
    (build-system gnu-build-system)
    (inputs (list gtk+ dbus dbus-glib))
    (arguments '(#:configure-flags '("--enable-gtk3=yes" "--enable-dbus=yes" )))
    (synopsis "LXDE GTK+ theme switcher")
    (description "LXAppearance is a desktop-independent GTK+ theme switcher
able to change themes, icons, and fonts used by GTK+ applications.
This version is compiled for supporting GTK+3 and dbus, and applies
patches from LXDE's github repos Merge Requests to work on wayland as well.")
    (home-page "https://lxde.github.io")
    (license license:gpl2+)))

(define-public nwg-launchers
  (package
    (name "nwg-launchers")
    (version "0.6.3")
    (source
     (origin
       (method git-fetch)
       (uri
        (git-reference
         (url "https://github.com/nwg-piotr/nwg-launchers")
         (commit (string-append "v" version))))
       (sha256
        (base32 "05aih05z5dybbv67qjmn90yjrk1k2l0v83hhglqqdin18k5xhq21"))))
    (build-system meson-build-system)
    (native-inputs
     (list git-minimal json-modern-cxx pkg-config))
    (inputs
     (list gtk-layer-shell gtkmm-3 librsvg))
    (synopsis "GTK-based launchers")
    (description "This package provides application grid, button bar and dmenu
for sway and other window managers.")
    (home-page "https://github.com/nwg-piotr/nwg-launchers")
    (license license:expat)))

(define-public swaynotificationcenter
  (let ((commit "3df4c34c5f0fd0fa3e56f6b605ae2d318b08aae6")
        (revision "0")
        (version "0.4"))
    (package
      (name "swaynotificationcenter")
      (version (git-version version revision commit))
      (source
       (origin
         (method git-fetch)
         (uri
          (git-reference
           (url "https://github.com/ErikReider/SwayNotificationCenter")
           (commit commit)))
         (sha256
          (base32 "0zr78k6rrjz4y18w2yv1v0m3aazkrr5y6v8ff32c4qjj7brgxr5d"))))
      (native-inputs
       (list `(,glib "bin") gobject-introspection pkg-config vala))
      (inputs
       (list glib gtk-layer-shell gtk+ json-glib
        libhandy wayland-protocols))
      (build-system meson-build-system)
      (synopsis "A simple notification daemon with a GTK gui built for
 Notifications and the control center")
      (description "Features
@itemize
@item Keyboard shortcuts
@item Notification body markup with image support
@item A panel to view previous notifications
@item Show album art for notifications like Spotify
@item Do not disturb
@item Click notification to execute default action
@item Show alternative notification actions
@item Customization through a CSS file
@item Trackpad/mouse gesture to close notification
@item The same features as any other basic notification daemon
@item Basic configuration through a JSON config file
@item Hot-reload config through swaync-client
@end itemize")
      (home-page "https://github.com/ErikReider/SwayNotificationCenter")
      (license license:expat))))

(define-public wapanel
  (package
   (name "wapanel")
   (version "1.1.0")
   (source
    (origin
     (method git-fetch)
     (uri
      (git-reference
       (url "https://www.github.com/firstbober/wapanel")
       (commit version)))
     (sha256
      (base32 "1d66jsnmgsjwnpq97lrkvb1zp0rp66120vpgw2zhbxwr2nbvnvxb"))))
   (build-system meson-build-system)
   (arguments `(#:glib-or-gtk? #t
                #:configure-flags '("-Dsystem_toml11=true")))
   (native-inputs
    (list wayland gobject-introspection pkg-config)) ;;wayland-scanner
   (inputs
    (list rus:toml11 wayland-protocols pulseaudio glib
          gtk-layer-shell gtkmm-3 libdrm wlroots wayland))
   (propagated-inputs (list xdg-utils))
   (home-page "https://firstbober.github.io/wapanel")
   (synopsis "Simple panel for your custom stacking Wayland-based desktop")
   (description "@{code}wapanel is a desktop-dedicated wayland panel/status bar/task bar for
wayfire and other wlroots based compositors. It is also compatible with Mir.")
   (license license:expat)))

(define-public wdisplays
  (package
   (name "wdisplays")
   (version "1.1")
   (source
    (origin
     (method url-fetch)
     (uri "https://github.com/artizirk/wdisplays/archive/refs/tags/1.1.tar.gz")
            (sha256
             (base32 "103gpg74fjqaaakx033axichaxdnnkvdfa1grbkqz4hdrvg3k9ss"))))
   (build-system meson-build-system)
   (arguments
    `(#:glib-or-gtk? #t
      #:modules ((guix build meson-build-system)
                 (guix build utils)
                 (srfi srfi-1))
      #:phases
      ;;fixes issue with finding libGLESv2.so....
      (modify-phases %standard-phases
        (add-after 'install 'mesa-wrap
        (lambda* (#:key outputs inputs #:allow-other-keys)
          (let* ((out (assoc-ref outputs "out"))
                (mesa (assoc-ref inputs "mesa")))
            (wrap-program (string-append out "/bin/wdisplays")
              `("LD_LIBRARY_PATH" ":" prefix
                (,(string-append mesa "/lib"))))) #t)))))
   (native-inputs (list `(,glib "bin") pkg-config))
   (inputs (list libepoxy wayland-protocols mesa  gtk+ wayland
                 wlroots python-scour))
   (home-page "https://github.com/artiirk/wdisplays")
   (synopsis "GTK+ display configuration GUI for Wayland")
   (description "@code{wdisplays} is a graphical application for configuring
 displays in Wayland compositors. It borrows some code from kanshi.
 It should work in any compositor that implements the wlr-output-
-management-unstable-v1 protocol.")
   (license license:gpl3+)))

(define-public wayland-protocols-latest
  (package
   (inherit wayland-protocols)
   (name "wayland-protocols-latest")
   (version "1.24")
   (source (origin
              (method url-fetch)
              (uri (string-append
                    "https://wayland.freedesktop.org/releases/"
                    "wayland-protocols-" version ".tar.xz"))
              (file-name (string-append name "-" version ".tar.xz"))
              (sha256
               (base32
                "1hlb6gvyqlmsdkv5179ccj07p04cn6xacjkgklakbszczv7xiw5z"))))))

(define-public libdrm-latest
  (package
   (inherit libdrm)
   (name "libdrm-latest")
   (version "2.4.111")
   (source (origin
            (method url-fetch)
            (uri (string-append
                  "https://dri.freedesktop.org/libdrm/libdrm-"
                  version ".tar.xz"))
            (file-name (string-append name "-" version ".tar.xz"))
            (sha256
             (base32
              "1adjg96mz0ghjzsgp9hrdr622shrvqmjcz5sxksfcka2fx7idmqs"))))))

(define-public libseat-seatd
  (package
    (inherit libseat)
    (name "libseat-seatd")
    (version "0.7.0")
    (source (origin
              (method git-fetch)
              (uri (git-reference
                    (url "https://git.sr.ht/~kennylevinsen/seatd")
                    (commit version)))
              (file-name (git-file-name name version))
              (sha256
               (base32
                "10f8387yy5as547xjjhl0cna6iywdgjmw0iq2nvcs8q6vlpnik4v"))))
    (arguments
     (list #:configure-flags
           #~(list "-Dlibseat-logind=disabled"
                   "-Dserver=disabled")))
    (propagated-inputs (list))))

(define-public wlroots-latest
  (package
   (inherit wlroots)
   (name "wlroots-latest")
   (version "0.15")
   (source (origin
            (method git-fetch)
            (uri (git-reference
                  (url "https://gitlab.freedesktop.org/wlroots/wlroots")
                  (commit version)))
            (file-name (git-file-name name version))
            (sha256
             (base32
              "00s73nhi3sc48l426jdlqwpclg41kx1hv0yk4yxhbzw19gqpfm1h"))))
   (propagated-inputs (modify-inputs (package-propagated-inputs wlroots)
                        (prepend libdrm-latest)
                        (replace "wayland-protocols"
                                 wayland-protocols-latest)))))

(define-public wlroots-seatd
  (package
   (inherit wlroots-latest)
   (name "wlroots-seatd")
   (propagated-inputs (modify-inputs (package-propagated-inputs wlroots-latest)
                        (replace "libseat" libseat-seatd)))))

(define-public sway-latest
  (package
   (inherit sway)
   (name "sway-latest")
   (version "1.7")
   (source (origin
            (method git-fetch)
            (uri (git-reference
                  (url "https://github.com/swaywm/sway")
                  (commit version)))
            (file-name (git-file-name name version))
            (sha256
             (base32
              "0ss3l258blyf2d0lwd7pi7ga1fxfj8pxhag058k7cmjhs3y30y5l"))))
   (inputs (modify-inputs (package-inputs sway)
             (prepend libdrm-latest)
             (replace "wlroots" wlroots-latest)))
   (native-inputs (modify-inputs (package-native-inputs sway)
                    (replace "wayland-protocols" wayland-protocols-latest)))))

(define-public sway-seatd
  (package
   (inherit sway-latest)
   (name "sway-seatd")
   (inputs (modify-inputs (package-inputs sway-latest)
             (replace "wlroots" wlroots-seatd)))))
